﻿using DataAccess.InternetBanking;
using FOModels.InternetBanking;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Bussiness.InternetBanking
{
    public class InternetBankingBLL
    {
        private InternetBankingDAL dal;
        public InternetBankingBLL()
        {
            dal = new InternetBankingDAL();
        }
        public List<InternetBankingModels> getInternetBankingbyProvider(int CompanyID, int langid)
        {
            List<InternetBankingModels> list = new List<InternetBankingModels>();
            InternetBankingModels fur;
            DataTable tb = dal.getInternetBankingbyProvider(CompanyID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new InternetBankingModels();
                    fur.InternetBankingID = int.Parse(row[0].ToString());
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.Cost = double.Parse(row[3].ToString());
                    fur.Interest = float.Parse(row[4].ToString());
                    fur.Display = bool.Parse(row[5].ToString());
                    fur.UserPost = row[6].ToString();
                    fur.DatePost = row[7].ToString();
                    fur.UserUpdate = row[8].ToString();
                    fur.DateUpdate = row[9].ToString();
                    fur.InternetBankingName = row[12].ToString();
                    fur.BenefitContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.FurtureContent = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[15].ToString());
                    fur.MoreBenefit = WebUtility.HtmlDecode(row[16].ToString());
                    fur.MoreFee = WebUtility.HtmlDecode(row[17].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[18].ToString());
                    fur.CompanyName = row[27].ToString();
                    fur.CompanyImg = row[20].ToString();

                    list.Add(fur);
                }
            }
            return list;
        }
        public int UpdateStatus(InternetBankingApplyModels card)
        {
            if (dal.UpdateStatus(card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteInternetBankingApply(int SavingDepositApplyID)
        {
            if (dal.DeleteInternetBankingApply(SavingDepositApplyID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InternetBankingApply(int InternetBankingID, InternetBankingApplyModels card)
        {
            if (dal.InternetBankingApply(InternetBankingID, card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public InternetBankingApplyModels getcontractbyid(int cardapplyid)
        {

            InternetBankingApplyModels fur = new InternetBankingApplyModels();
            DataTable tb = dal.getcontractbyid(cardapplyid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new InternetBankingApplyModels();
                    fur.InternetBankingApplyID = int.Parse(row[0].ToString());
                    fur.InternetBankingID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.CurrentAccount = bool.Parse(row[7].ToString());
                    fur.SavingsDeposits = bool.Parse(row[8].ToString());
                    fur.CreditCard = bool.Parse(row[9].ToString());
                    fur.HomeLoan = bool.Parse(row[10].ToString());
                    fur.CarLoan = bool.Parse(row[11].ToString());
                    fur.PersonalLoan = bool.Parse(row[12].ToString());
                    fur.BusinessLoan = bool.Parse(row[13].ToString());
                    fur.City = row[14].ToString();
                    fur.ContactTime = row[15].ToString();
                    fur.StatusID = int.Parse(row[16].ToString());
                    fur.AppDate = row[17].ToString();
                    fur.InternetBankingName = row[19].ToString();
                    fur.CompanyImg = row[31].ToString();
                    fur.CompanyName = row[38].ToString();
                    fur.StatusName = row[29].ToString();
                }
            }
            return fur;
        }
        public List<InternetBankingApplyModels> getcontractbystatuscount(int statusid)
        {
            List<InternetBankingApplyModels> list = new List<InternetBankingApplyModels>();
            InternetBankingApplyModels fur;
            DataTable tb = dal.getcontractbystatuscount(statusid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new InternetBankingApplyModels();
                    fur.InternetBankingApplyID = int.Parse(row[0].ToString());
                    fur.InternetBankingID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.CurrentAccount = bool.Parse(row[7].ToString());
                    fur.SavingsDeposits = bool.Parse(row[8].ToString());
                    fur.CreditCard = bool.Parse(row[9].ToString());
                    fur.HomeLoan = bool.Parse(row[10].ToString());
                    fur.CarLoan = bool.Parse(row[11].ToString());
                    fur.PersonalLoan = bool.Parse(row[12].ToString());
                    fur.BusinessLoan = bool.Parse(row[13].ToString());
                    fur.City = row[14].ToString();
                    fur.ContactTime = row[15].ToString();
                    fur.StatusID = int.Parse(row[16].ToString());
                    fur.AppDate = row[17].ToString();
                    fur.InternetBankingName = row[19].ToString();
                    fur.CompanyImg = row[31].ToString();
                    fur.CompanyName = row[38].ToString();
                    fur.StatusName = row[29].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<InternetBankingApplyModels> getcontract()
        {
            List<InternetBankingApplyModels> list = new List<InternetBankingApplyModels>();
            InternetBankingApplyModels fur;
            DataTable tb = dal.getcontract();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new InternetBankingApplyModels();
                    fur.InternetBankingApplyID = int.Parse(row[0].ToString());
                    fur.InternetBankingID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.CurrentAccount = bool.Parse(row[7].ToString());
                    fur.SavingsDeposits = bool.Parse(row[8].ToString());
                    fur.CreditCard = bool.Parse(row[9].ToString());
                    fur.HomeLoan = bool.Parse(row[10].ToString());
                    fur.CarLoan = bool.Parse(row[11].ToString());
                    fur.PersonalLoan = bool.Parse(row[12].ToString());
                    fur.BusinessLoan = bool.Parse(row[13].ToString());
                    fur.City = row[14].ToString();
                    fur.ContactTime = row[15].ToString();
                    fur.StatusID = int.Parse(row[16].ToString());
                    fur.AppDate = row[17].ToString();
                    fur.InternetBankingName = row[19].ToString();
                    fur.CompanyImg = row[31].ToString();
                    fur.CompanyName = row[38].ToString();
                    fur.StatusName = row[29].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<InternetBankingApplyModels> getcontractbystatus(int statusid)
        {
            List<InternetBankingApplyModels> list = new List<InternetBankingApplyModels>();
            InternetBankingApplyModels fur;
            DataTable tb = dal.getcontractbystatus(statusid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new InternetBankingApplyModels();
                    fur.InternetBankingApplyID = int.Parse(row[0].ToString());
                    fur.InternetBankingID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.CurrentAccount = bool.Parse(row[7].ToString());
                    fur.SavingsDeposits = bool.Parse(row[8].ToString());
                    fur.CreditCard = bool.Parse(row[9].ToString());
                    fur.HomeLoan = bool.Parse(row[10].ToString());
                    fur.CarLoan = bool.Parse(row[11].ToString());
                    fur.PersonalLoan = bool.Parse(row[12].ToString());
                    fur.BusinessLoan = bool.Parse(row[13].ToString());
                    fur.City = row[14].ToString();
                    fur.ContactTime = row[15].ToString();
                    fur.StatusID = int.Parse(row[16].ToString());
                    fur.AppDate = row[17].ToString();
                    fur.InternetBankingName = row[19].ToString();
                    fur.CompanyImg = row[31].ToString();
                    fur.CompanyName = row[38].ToString();
                    fur.StatusName = row[29].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<InternetBankingModels> getInternetBankingList(int langid)
        {
            List<InternetBankingModels> list = new List<InternetBankingModels>();
            InternetBankingModels fur;
            DataTable tb = dal.getInternetBankingList(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new InternetBankingModels();
                    fur.InternetBankingID = int.Parse(row[0].ToString());
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.Cost = double.Parse(row[3].ToString());
                    fur.Interest = float.Parse(row[4].ToString());
                    fur.Display = bool.Parse(row[5].ToString());
                    fur.UserPost = row[6].ToString();
                    fur.DatePost = row[7].ToString();
                    fur.UserUpdate = row[8].ToString();
                    fur.DateUpdate = row[9].ToString();
                    fur.InternetBankingName = row[12].ToString();
                    fur.BenefitContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.FurtureContent = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[15].ToString());
                    fur.MoreBenefit = WebUtility.HtmlDecode(row[16].ToString());
                    fur.MoreFee = WebUtility.HtmlDecode(row[17].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[18].ToString());
                    fur.CompanyName = row[27].ToString();
                    fur.CompanyImg = row[20].ToString();

                    list.Add(fur);
                }
            }
            return list;
        }
        public List<InternetBankingModels> GetAllToManager(int langid)
        {
            List<InternetBankingModels> list = new List<InternetBankingModels>();
            InternetBankingModels fur;
            DataTable tb = dal.GetAllToManager(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {

                    fur = new InternetBankingModels();
                    fur.InternetBankingID = int.Parse(row[0].ToString());
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.Cost = double.Parse(row[3].ToString());
                    fur.Interest = float.Parse(row[4].ToString());
                    fur.Display = bool.Parse(row[5].ToString());
                    fur.UserPost = row[6].ToString();
                    fur.DatePost = row[7].ToString();
                    fur.UserUpdate = row[8].ToString();
                    fur.DateUpdate = row[9].ToString();
                    fur.InternetBankingName = row[12].ToString();
                    fur.CompanyName = row[27].ToString();
                    fur.CompanyImg = row[20].ToString();
                    fur.FlagImage = row[32].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public InternetBankingModels GetInternetBankingByIDToManager(int CardID, int langid)
        {
            InternetBankingModels fur = new InternetBankingModels();
            DataTable tb = dal.GetInternetBankingByIDToManager(CardID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur.InternetBankingID = int.Parse(row[0].ToString());
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.Cost = double.Parse(row[3].ToString());
                    fur.Interest = float.Parse(row[4].ToString());
                    fur.Display = bool.Parse(row[5].ToString());
                    fur.UserPost = row[6].ToString();
                    fur.DatePost = row[7].ToString();
                    fur.UserUpdate = row[8].ToString();
                    fur.DateUpdate = row[9].ToString();
                    fur.InternetBankingName = row[12].ToString();
                    fur.BenefitContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.FurtureContent = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[15].ToString());
                    fur.MoreBenefit = WebUtility.HtmlDecode(row[16].ToString());
                    fur.MoreFee = WebUtility.HtmlDecode(row[17].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[18].ToString());
                    fur.CompanyName = row[27].ToString();
                    fur.CompanyImg = row[20].ToString();
                }
                return fur;
            }
            else
                return null;
        }
        public InternetBankingModels GetInternetBankingByID(int CardID, int langid)
        {
            InternetBankingModels fur = new InternetBankingModels();
            DataTable tb = dal.GetInternetBankingByID(CardID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur.InternetBankingID = int.Parse(row[0].ToString());
                    fur.CompanyID = int.Parse(row[2].ToString());
                    fur.Cost = double.Parse(row[3].ToString());
                    fur.Interest = float.Parse(row[4].ToString());
                    fur.Display = bool.Parse(row[5].ToString());
                    fur.UserPost = row[6].ToString();
                    fur.DatePost = row[7].ToString();
                    fur.UserUpdate = row[8].ToString();
                    fur.DateUpdate = row[9].ToString();
                    fur.InternetBankingName = row[12].ToString();
                    fur.BenefitContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.FurtureContent = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[15].ToString());
                    fur.MoreBenefit = WebUtility.HtmlDecode(row[16].ToString());
                    fur.MoreFee = WebUtility.HtmlDecode(row[17].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[18].ToString());
                    fur.CompanyName = row[27].ToString();
                    fur.CompanyImg = row[20].ToString();
                }
                return fur;
            }
            else
                return null;
        }
        public InternetBankingModels getTOP1()
        {
            InternetBankingModels fur = new InternetBankingModels();
            DataTable tb = dal.getTOP1();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur.InternetBankingID = int.Parse(row[0].ToString());
                }
                return fur;
            }
            else
            {
                return null;
            }

        }
        public int InsertInternetBanking(InternetBankingModels models)
        {
            if (dal.InsertInternetBanking(models) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertInternetBankingLanng(InternetBankingModels models, int langid)
        {
            if (dal.InsertInternetBankingLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int UpdateInternetBanking(InternetBankingModels card, int langid)
        {
            if (dal.UpdateInternetBanking(card) > 0 && dal.UpdateInternetBankingLang(card, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteInternetBanking(int InternetBankingID)
        {
            if (dal.DeleteInternetBanking(InternetBankingID) > 0 && dal.DeleteInternetBankingLang(InternetBankingID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }
}
